package com.ait.edu.controller;

import com.ait.commonutils.Msg;
import com.ait.edu.entity.Course;
import com.ait.edu.entity.Subject;
import com.ait.edu.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/eduservice/dashboard")
public class DashboardController {

    //讲师
    @Autowired
    private TeacherService teacherService;

    //课程
    @Autowired
    private CourseService courseService;

    //课程视频
    @Autowired
    private VideoService videoService;

    //课程科目
    @Autowired
    private SubjectService subjectService;

    //课程章节
    @Autowired
    private ChapterService chapterService;



    @GetMapping("getCOUNTAll")
    public Msg getCOUNTAll(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("teachercount",teacherService.count(null));
        map.put("coursecount",courseService.count(null));
        map.put("videocount",videoService.count(null));
        QueryWrapper<Subject> wrapper = new QueryWrapper<Subject>();
        wrapper.ne("parent_id","0");
        map.put("subjectcount",subjectService.count(wrapper));
        map.put("chaptercount",chapterService.count(null));
        return Msg.success().data(map);
    }

    //release
    @GetMapping("getRelease")
    public Msg getRelease(){
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("status","Normal");
        int count = courseService.count(wrapper);
        if (count>0) {
            return Msg.success().data("course",count);
        }
        return Msg.fail();
    }


    //视频销量
    @GetMapping("getvolume")
    public Msg getvolume(){
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("buy_count");
        wrapper.last("LIMIT 6");
        List<Course> count = courseService.list(wrapper);
        if (count.get(0).getBuyCount()>0)
            return Msg.success().data("list",count);

        return Msg.fail();
    }


}
